﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Xml;

namespace RTW.Web.Handler
{
    public static class CommHandler
    {

        public static string DateFormatToString(DateTime dt)

        {

            //TimeSpan表示时间间隔

            TimeSpan span = (DateTime.Now - dt).Duration();//表示取timespan绝对值
            if (span.TotalDays > 60)
            {
                return dt.ToString("yyyy-MM-dd");
            }
            else if (span.TotalDays > 30)
            {
                return "1个月前";
            }
            else if (span.TotalDays > 14)
            {
                return "2周前";
            }
            else if (span.TotalDays > 7)
            {
                return "1周前";
            }
            else if (span.TotalDays > 1)
            {
                return string.Format("{0}天前", (int)Math.Floor(span.TotalDays));
            }
            else if (span.TotalHours > 1)
            {
                return string.Format("{0}小时前", (int)Math.Floor(span.TotalHours));
            }
            else if (span.TotalMinutes > 1)
            {
                return string.Format("{0}分钟前", (int)Math.Floor(span.TotalMinutes));
            }
            else if (span.TotalSeconds >= 1)
            {
                return string.Format("{0}秒前", (int)Math.Floor(span.TotalSeconds));
            }
            else
            {
                return "1秒前";
            }

        }


        public static string GetBgName(int itemIndex)
        {
            string[] arry = { "blue", "lazur", "yellow", "navy" };
            //int index = new Random().Next(0, arry.Length); //生成随机下标
            if (itemIndex > arry.Length - 1)
            {
                return arry[itemIndex / arry.Length];
            }
            else
            {
                return arry[itemIndex];
            }
        }

        public static string GetMenuBgName(int itemIndex)
        {
            string[] arry = { "navy-bg", "red-bg", "lazur-bg", "yellow-bg", "blue-bg", "zui-bg1", "zui-bg2", "zui-bg3", "zui-bg4", "zui-bg5", "zui-bg6", "zui-bg7" };

            if (itemIndex > arry.Length - 1)
            {
                return arry[itemIndex / arry.Length];
            }
            else
            {
                return arry[itemIndex];
            }
        }
    }
}
